package com.smh.a05XmlDemo3;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class XpathDemo1 {
    public static void main(String[] args) throws DocumentException {

        SAXReader saxReader = new SAXReader();
        File file = new File("day32-code\\src\\com\\smh\\a04XmlDemo2\\users.xml");
        Document document = saxReader.read(file);

        //获取一个
        Node node = document.selectSingleNode("/users/user/name");
        System.out.println(node);
        System.out.println(node.getText());

        //获取所有
        List<Element> list = document.selectNodes("/users/user/name");

        for (Element element : list) {
            System.out.println(element.getText());
        }

    }
}
